﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SystemMHB.API.Application.Command.ReturnWarehouseCommand;
using SystemMHB.API.DTOs;
using SystemMHB.Domian;
using SystemMHB.Domian.DTO;

namespace SystemMHB.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReturnWarehouseController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<ReturnWarehouseController> logger;
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public ReturnWarehouseController(ILogger<ReturnWarehouseController> logger, IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加返库信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ReturnWarehouseAdd(ReturnWarehouseAddCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 修改返库状态信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ReturnWarehouseUpdate(ReturnWarehouseUpdateCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 删除返库信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ReturnWarehouseDelete(ReturnWarehouseDeleteCommand request)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示返库信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PagingDTO<ReturnWarehouse>>> ReturnWarehouseShow([FromQuery]ReturnWarehouseShowCommand request)
        {
            ApiResult<PagingDTO<ReturnWarehouse>> result = new ApiResult<PagingDTO<ReturnWarehouse>>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 返库信息详情
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ReturnWarehouse>> ReturnWarehouseFantian([FromQuery]ReturnWarehouseFantianCommand request)
        {
            ApiResult<ReturnWarehouse> result = new ApiResult<ReturnWarehouse>();
            try
            {
                result.Data = await mediator.Send(request);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
    }
}
